package com.geekband.Test01;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

/**
 * Function:
 * Create date on 15/11/12.
 *
 * @author Conquer
 * @version 1.0
 */
public class TestFragmentActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_test);

        FragmentManager fragmentManager = getFragmentManager();

        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        // 创建一个fragment对象实例
        TestFragment testFragment = TestFragment.newInstance("我是极客班",15);

        // 将其添加到ViewGroup
        fragmentTransaction.add(R.id.fragment_view, testFragment, "test_fragment_tag");

        // 将其移除
//        fragmentTransaction.remove(testFragment).commit();

        // 找到我们的Fragment

        Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_test);


        fragmentManager.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
            @Override
            public void onBackStackChanged() {

            }
        });
        if(fragment instanceof TestFragment){
            // TODO: DO your action
        } else {
            throw new IllegalStateException("is not testFragment");
        }

    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();

    }
}
